<template>
	<div class="newdizhi">
		<!-- 顶部返回 -->
		<van-nav-bar
		  title="新增地址"
		  left-arrow
		  @click-left="$router.go(-1)"
		/>
		<!-- 地址选择区 -->
		<van-address-edit
		  :area-list="areaList"
		  show-postal
		  show-set-default
		  show-search-result
		  :search-result="searchResult"
		  :area-columns-placeholder="['请选择', '请选择', '请选择']"
		  @save="onSave"
		/>
	</div>
</template>

<script>
	import {addAddressApi} from '@/api'
	import areaList from '../area'
	import {mapState} from 'vuex'
	export default {
		name:'newdizhi',
		data() {
		    return {
		      areaList,
		      searchResult: [],
		    }
		  },
		  computed:{
			  ...mapState(['isDenglu']),
		  },
		  created(){
		  },
		  methods: {
		    async onSave(content) {
				let {
					addressDetail:address_area_detail,
					name:address_name,
					tel:address_phone,
					postalCode:address_post_code,
					isDefault:address_tag,
					areaCode,
					city,
					county,
					province,
				} = content
				let address_area = province+city+county
				let {token:user_id} = this.isDenglu
				let addressDetail = {address_area_detail,address_name,address_phone,address_post_code,address_tag,areaCode,city,county,province,address_area,user_id}
				let res = await addAddressApi(addressDetail)
				if(res.data.success_code === 200){
					this.$router.go(-1)
				}
		    }
		}
	}
</script>

<style scoped lang="less">
	.newdizhi{
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 1000;
		background-color: #fff;
	}
</style>